const { app,BrowserWindow,ipcMain } =  require('electron')
const path  = require('path')

const createWindow = ()=>{
    const win = new BrowserWindow({
        width:1100,
        height:700,
        webPreferences:{
          nodeIntegration:true, // 禁用 nodeIntegration
          contextIsolation: true, // 启用上下文隔离 
          preload:path.join(__dirname,'./preload.js')
        }
    })
    //关闭菜单
    win.setMenu(null)
    if(process.env.VITE_DEV_SERVER_URL){
        win.loadURL(process.env.VITE_DEV_SERVER_URL)
    }else{
        win.loadFile(path.join(__dirname,'../dist/index.html'))
    }
}


ipcMain.on('great',(event,val)=>{
  console.log(val)
})

app.whenReady().then(() => {
    createWindow()
    app.on('activate', () => {
      if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
  })

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') app.quit()
})